import React from 'react';
import * as datetime from '@/utils/datetime';
import regs from '@/utils/regs';
import { useModel } from 'umi';
import Workflow from '@/components/page/Workflow';

const columns: API.Column[] = [
  {
    title: '申请时间',
    key: 'sqsj',
    dataType: 'date',
    render: (sqsj: any) => datetime.format(sqsj, 'yyyy-MM-dd'),
    width: 120,
    sorter: true,
    dispaly: true,
    filter: true,
  },
  {
    title: '原工号',
    key: 'sysuseridy',
    dataIndex: 'sysuseridy',
    width: 120,
    sorter: true,
    dispaly: true,
    filter: true,
  },
  {
    title: '姓名',
    key: 'userName',
    dataIndex: 'userName',
    width: 120,
    sorter: true,
    dispaly: true,
  },
  {
    title: '部门',
    key: 'organName',
    dataIndex: 'organName',
    width: 120,
    sorter: true,
    dispaly: true,
  },
  {
    title: '新工号',
    key: 'sysuseridx',
    dataIndex: 'sysuseridx',
    width: 120,
    sorter: true,
    dispaly: true,
    filter: true,
  },
];

const SpGhbg: React.FC = () => {
  const { user } = useModel('@@initialState', (ret) => ({
    user: ret.initialState?.user,
  }));
  if (!user) {
    return <></>;
  }
  const controls: API.Control[] = [
    {
      name: 'sysuseridy',
      label: '原工号',
      rules: [
        { required: true, message: '员工编号不能为空' },
        { min: 6, max: 10, message: '长度不能小于6，大于10' },
        { pattern: regs.alphanum, message: '必须是字母或者数字' },
      ],
      initValue: user!.no,
      disabled: true,
      type: 'text',
      dataType: 'string',
      grid: 12 / 24,
    },
    {
      name: 'userName',
      label: '员工名称',
      rules: [
        { required: true, message: '员工名称不能为空' },
        { min: 2, max: 10, message: '长度不能小于2，大于30' },
      ],
      initValue: user!.name,
      disabled: true,
      type: 'text',
      dataType: 'string',
      grid: 12 / 24,
    },
    {
      name: 'sysuseridx',
      label: '新工号',
      rules: [
        { required: true, message: '员工编号不能为空' },
        { min: 6, max: 10, message: '长度不能小于6，大于10' },
        { pattern: regs.alphanum, message: '必须是字母或者数字' },
      ],
      type: 'text',
      dataType: 'string',
      grid: 12 / 24,
    },
  ];
  return (
    <Workflow
      taskDaoName="SpGhbg"
      taskColumns={columns}
      taskControls={controls}
      initSorter={{ FieldName: 'SQSJ', Direction: 'ASC' }}
      title="工号变更申请"
      titleColNames={['sysuserid', 'sysusername']}
      keyColName="frid"
      canAdd={true}
      canUpdate={false}
      canDelete={true}
    />
  );
};

export default SpGhbg;
